<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增稿件管理')"/>
    <script type="text/javascript" th:src="@{/pdata/pdata.js}"></script>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-paper-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">稿件名称：</label>
            <div class="col-sm-8">
                <input name="paperName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">客户名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input type="text" class="form-control" id="suggest-demo-2">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">原始链接：</label>
            <div class="col-sm-8">
                <input name="originalLink" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">上传稿件：</label>
            <div class="col-sm-8">
                <input type="hidden" name="uploadFile">
                <div class="file-loading">
                    <input class="form-control file-upload" id="uploadFile" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">回款周期：</label>
            <div class="col-sm-8">
                <input name="paybackPeriod" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>

    </form>
    <div class="row">
        要发布的媒体
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="mediaSearch">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>业务类型：</label>
                            <select name="mediaType" class="form-control m-b"
                                    th:with="type=${@dict.getType('work_paper_type')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>分类：</label>
                            <select name="category" class="form-control m-b"
                                    th:with="type=${@dict.getType('work_category')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>行业：</label>
                            <input type="text" name="companyName"/>
                        </li>
                        <li>
                            <label>媒体名称：</label>
                            <input type="text" name="mediaName"/>
                        </li>
                        <li>
                            <label>平台：</label>
                            <select name="platform" class="form-control m-b"
                                    th:with="type=${@dict.getType('work_platform')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>价格范围：</label>
                            <input type="text" name="startPrice" width="50"/>
                            -
                            <input type="text" name="endPrice" width="50"/>
                        </li>

                        <li>
                            <label>地区：</label>
                            <select name="province" id="province" class="form-control">
                            </select>
                        </li>
                        <li>
                            <select name="city" id="city" class="form-control">
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="commonSearch();"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$('#mediaSearch')[0].reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success" onclick="insertRow()"><i class="fa fa-plus"></i> 批量选择</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="media-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: bootstrap-suggest-js"/>
<th:block th:include="include :: bootstrap-typeahead-js"/>
<script th:inline="javascript">
    var prefix = ctx + "work/paper"
    var categoryDatas = [[${@dict.getType('work_category')}]];
    var authDatas = [[${@dict.getType('work_auth')}]];
    var industryDatas = [[${@dict.getType('work_industry')}]];
    var includedDatas = [[${@dict.getType('work_included')}]];
    var linkDatas = [[${@dict.getType('work_publish_link')}]];
    var weekendPressDatas = [[${@dict.getType('work_publish_paper')}]];
    var publishDatas = [[${@dict.getType('work_publish_date')}]];
    var plusVDatas = [[${@dict.getType('work_plus_v')}]];
    var isMasterDatas = [[${@dict.getType('sys_yes_no')}]];
    var platformDatas = [[${@dict.getType('work_platform')}]];
    var isDirectDatas = [[${@dict.getType('sys_yes_no')}]];
    var vOriginalDatas = [[${@dict.getType('work_original_v')}]];

    $("#form-paper-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-paper-add').serialize());
        }
    }

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })


    var testBsSuggest = $("#suggest-demo-2").bsSuggest({
        url: "/work/customer/query",
        showBtn: false,
        idField: "customerId",
        keyField: "customerName",
        effectiveFields: ["customerId", "customerName", "companyName", "createTime"],
        effectiveFieldsAlias: {customerId: "ID", customerName: "客户名称", companyName: "公司名称", createTime: "登记时间"},
        showHeader: true
    }).on('onDataRequestSuccess', function (e, result) {
        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword) {
        console.log('onSetSelectValue: ', keyword);
    }).on('onUnsetSelectValue', function (e) {
        console.log("onUnsetSelectValue");
    });

    $(function () {
        var html = "<option value=''>== 请选择 ==</option>";
        $("#city").append(html);

        $.each(pdata, function (idx, item) {
            if (parseInt(item.level) == 0) {
                html += "<option value='" + item.names + "' exid='" + item.code + "'>" + item.names + "</option>";
            }
        });
        $("#province").append(html);

        $("#province").change(function () {
            if ($(this).val() == "") return;
            $("#city option").remove();

            var code = $(this).find("option:selected").attr("exid");
            code = code.substring(0, 2);
            var html = "<option value=''>== 请选择 ==</option>";

            $.each(pdata, function (idx, item) {
                if (parseInt(item.level) == 1 && code == item.code.substring(0, 2)) {
                    html += "<option value='" + item.names + "' exid='" + item.code + "'>" + item.names + "</option>";
                }
            });
            $("#city").append(html);
        });


        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            uniqueId: "userId",
            height: 400,
            columns: [{
                checkbox: true
            },
                {
                    field: 'Id',
                    title: '编号'
                },
                {
                    field: 'mediaType',
                    title: '业务类型'
                },
                {
                    field: 'platform',
                    title: '平台'
                },
                {
                    field: 'mediaName',
                    title: '媒体名称'
                },
                {
                    field: 'price',
                    title: '总价'
                },
                {
                    field: 'priceType',
                    title: '价格类型'
                },

                {
                    field: 'words',
                    title: '字数'
                },
                {
                    field: 'actualPrice',
                    title: '实际总价'
                }, {
                    field: 'flowDetail',
                    title: '添加刷量详细'
                }, {
                    field: 'flowRemark',
                    title: '刷量内容备注'
                },
                {
                    field: 'flowrLink',
                    title: '刷量链接(不发稿，单独刷量时填写)'
                },
            ]
        };

        $.table.init(options);

    });

    /* 新增表格行 */
    function insertRow() {
        var randomId = 100 + ~~(Math.random() * 100)
        var row=$("#media-table").bootstrapTable('getSelections');
        console.log(row)
        $("#" + table.options.id).bootstrapTable('insertRow', {
            index: 0, // 你想插入到哪，0表示第一行
            row: {
                Id: randomId,
                mediaType: $("#mediaSearch [name='mediaType']").val(),
                platform: (row.platform)?row.platform:'',
                mediaName: row.mediaName,
                userEmail: 'ry1@qq.com',
                userBalance: 10 + randomId,
            }
        })
    }

    function commonSearch() {
        var mt = $("#mediaSearch [name='mediaType']").val();
        var pre = ctx;
        var options = {};

        switch (mt) {
            case "1":
                pre = pre + "work/net";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'netId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'netName',
                            title: '媒体名称'
                        },
                        {
                            field: 'province',
                            title: '省份'
                        },
                        {
                            field: 'city',
                            title: '地市'
                        },
                        {
                            field: 'category',
                            title: '分类',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(categoryDatas, value);
                            }
                        },
                        {
                            field: 'industry',
                            title: '行业',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(industryDatas, value);
                            }
                        },
                        {
                            field: 'included',
                            title: '收录',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(includedDatas, value);
                            }
                        },
                        {
                            field: 'price',
                            title: '价格'
                        },
                        {
                            field: 'link',
                            title: '发布链接',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(linkDatas, value);
                            }
                        },
                        {
                            field: 'weekendPress',
                            title: '周末发稿',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(weekendPressDatas, value);
                            }
                        },
                        {
                            field: 'mediaCase',
                            title: '案例'
                        },
                        {
                            field: 'publish',
                            title: '出稿日期',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(publishDatas, value);
                            }
                        },
                        {
                            field: 'contacts',
                            title: '联系人'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            case "2":
                pre = pre + "work/wb";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'wbId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'wbName',
                            title: '微博名称'
                        },
                        {
                            field: 'province',
                            title: '省份'
                        },
                        {
                            field: 'city',
                            title: '地市'
                        },
                        {
                            field: 'industry',
                            title: '行业',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(industryDatas, value);
                            }
                        },
                        {
                            field: 'plusV',
                            title: '加V',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(plusVDatas, value);
                            }
                        },
                        {
                            field: 'fans',
                            title: '粉丝数(万)'
                        },
                        {
                            field: 'link',
                            title: '链接'
                        },
                        {
                            field: 'wDirectPrice',
                            title: '微任务直发价'
                        },
                        {
                            field: 'wForwardPrice',
                            title: '微任务转发价'
                        },
                        {
                            field: 'directPrice',
                            title: '直发价'
                        },
                        {
                            field: 'forwardPrice',
                            title: '转发价'
                        },
                        {
                            field: 'contacts',
                            title: '联系人'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            case "3":
                pre = pre + "work/wx";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'wxId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'wxName',
                            title: '微信名称'
                        },
                        {
                            field: 'wxNo',
                            title: '微信号'
                        },
                        {
                            field: 'province',
                            title: '省份'
                        },
                        {
                            field: 'city',
                            title: '地市'
                        },
                        {
                            field: 'category',
                            title: '分类',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(categoryDatas, value);
                            }
                        },
                        {
                            field: 'fans',
                            title: '粉丝数(万)'
                        },
                        {
                            field: 'auth',
                            title: '认证',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(authDatas, value);
                            }
                        },
                        {
                            field: 'readCount',
                            title: '阅读量'
                        },
                        {
                            field: 'leadPrice',
                            title: '头条'
                        },
                        {
                            field: 'secondPrice',
                            title: '次条'
                        },

                        {
                            field: 'remark',
                            title: '备注'
                        },
                        {
                            field: 'createBy',
                            title: '登记人'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            case "4":
                pre = pre + "work/plane";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'planeId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'planeName',
                            title: '媒体名称'
                        },
                        {
                            field: 'province',
                            title: '省份'
                        },
                        {
                            field: 'city',
                            title: '地市'
                        },
                        {
                            field: 'industry',
                            title: '行业',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(industryDatas, value);
                            }
                        },
                        {
                            field: 'isMaster',
                            title: '是否主报',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(isMasterDatas, value);
                            }
                        },
                        {
                            field: 'price',
                            title: '单价'
                        },
                        {
                            field: 'contacts',
                            title: '联系人'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        },
                        {
                            field: 'createBy',
                            title: '登记人'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            case "5":
                pre = pre + "work/app";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'appId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'platform',
                            title: '平台',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(platformDatas, value);
                            }
                        },
                        {
                            field: 'mediaName',
                            title: '媒体名称'
                        },
                        {
                            field: 'industry',
                            title: '行业',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(industryDatas, value);
                            }
                        },
                        {
                            field: 'price',
                            title: '价格'
                        },
                        {
                            field: 'mediaCase',
                            title: '案例'
                        },
                        {
                            field: 'publish',
                            title: '出稿日期',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(publishDatas, value);
                            }
                        },
                        {
                            field: 'link',
                            title: '链接'
                        },
                        {
                            field: 'vOriginal',
                            title: '加V原创',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(vOriginalDatas, value);
                            }
                        },
                        {
                            field: 'fans',
                            title: '粉丝数(万)'
                        },
                        {
                            field: 'weekendPress',
                            title: '周末发稿',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(weekendPressDatas, value);
                            }
                        },
                        {
                            field: 'status',
                            title: '状态'
                        },
                        {
                            field: 'introduction',
                            title: '简介'
                        },
                        {
                            field: 'contacts',
                            title: '联系人'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        },
                        {
                            field: 'createBy',
                            title: '登记人'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            case "6":
                pre = pre + "work/flow";
                options = {
                    url: pre + "/list",
                    id: "media-table",
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'flowId',
                            title: '媒体ID',
                            visible: false
                        },
                        {
                            field: 'platform',
                            title: '平台',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(platformDatas, value);
                            }
                        },
                        {
                            field: 'category',
                            title: '分类',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(categoryDatas, value);
                            }
                        },
                        {
                            field: 'isDirect',
                            title: '是否直营',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(isDirectDatas, value);
                            }
                        },
                        {
                            field: 'contacts',
                            title: '联系人'
                        },
                        {
                            field: 'status',
                            title: '状态'
                        },
                        {
                            field: 'remark',
                            title: '备注'
                        },
                        {
                            field: 'createBy',
                            title: '登记人'
                        }]
                };
                $.table.destroy('media-table');
                $.table.init(options);
                break;
            default:
                alert('error')
        }
    }


</script>
</body>
</html>